
import { uniqueId } from '../utils/uniqueId';

export const parse = (mixedJson) => {
    //console.log(mixedJson,'mixedJson');
    
    return mixedJson
         //过滤掉空或者null元素
         //.filter(item => { return ((item != undefined) && (item != null)); })
         .map(item => {
         //console.log(item, 'item');
        const {
            id,//控件面板里控件id代表控件类型
            type,
            name,
            control,
            container,
            selected,
            chosen,
            //默认属性
            defaultAttrs,
            ...otherAttrs
        } = item;

        if (control) {
            if (container) {
                return {
                    code: uniqueId(),
                    type: type,
                    name: name,
                    attrs:{...defaultAttrs},
                    children: [],
                    ...otherAttrs
                };
            } else {
                return {
                    code: uniqueId(),
                    type: type,
                    name: name,
                    attrs:{...defaultAttrs},
                    ...otherAttrs
                };
            }

        } else {
            return {
                type: type,
                name: name,
                ...otherAttrs
            };
        }
    });
}